package com.zky.DAO.impl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zky.common.HibernateSessionFactory;
import com.zky.entity.Users;

@SuppressWarnings("serial")
public class ssh1 extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	@SuppressWarnings("unchecked")
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		List<Users> list=new ArrayList<Users>();
		String name1=request.getParameter("username");
		 Session session = HibernateSessionFactory.getSession();
		 Transaction transaction = session.beginTransaction();		
		  try{
			  String hql="from Users1 as muser where muser.username=?";
			  Query query=session.createQuery(hql);
			  query.setString(0, name1);
			  String ms="";
			   list=query.list();
				if (null == list || list.size() == 0) {
					ms="用户名已存在";
			    	System.out.print("ms");
			    }
				else{
					ms="";
					System.out.print(ms);
				}
			   transaction.commit();
			   
			   }catch(Exception e){
			    e.printStackTrace();
			   }finally{
			    session.close();
		
	}
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		out.flush();
		out.close();
	}

}
